package com.algorithms.JKTime.array.LongestSubstringWithoutRepeatingCharacters;// 3. Longest Substring Without Repeating Characters
// https://leetcode.com/problems/longest-substring-without-repeating-characters/description/


import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

// 时间复杂度: O(len(s))
// 空间复杂度: O(len(charset))
public class Solution8 {

    public int removeDuplicates(int[] nums) {
        int n = nums.length;
        if (n <= 2)
          return n;

        int i = 1;
        int k = i - 1;
        int j = i + 1;

        while( j <= n-1){
            if ((nums[j] != nums[i]) || (nums[j] == nums[i] && nums[j] != nums[k])){
                k = i;
                nums[i+1] = nums[j];
                i += 1;
            }

            j += 1;

        }
        return i + 1;
    }

    public static void main(String[] args) {
        int[] num_1 = {1,1,1,2,2,3};
        int[] num_2 = {0,0,1,1,1,1,2,3,3,4,5,5,5};
        System.out.println((new Solution8()).removeDuplicates( num_1 )+"   "+ Arrays.toString(num_1));
        System.out.println((new Solution8()).removeDuplicates(num_2)+"   "+ Arrays.toString(num_2));
    }
}
